<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>书籍评论</title>
<!-- 引入css样式文件 -->
<!-- Bootstrap Core CSS -->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
<!-- MetisMenu CSS -->
<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
<!-- DataTables CSS -->
<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
<!-- Custom CSS -->
<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
<!-- Custom Fonts -->
<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet"
	type="text/css" />
<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet"
	type="text/css" />
<style>
body {
	padding-top: 20px;
}

.table thead {
	background-color: #f5f5f5;
}
</style>
</head>
<body>

	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">书籍评论</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		
				<a href="#" class="btn btn-primary" data-toggle="modal"
			data-target="#newReviewDialog" onclick="clearReview()">新建</a>
		
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get"
					action="${pageContext.request.contextPath }/review/list.action">
					<button type="submit" class="btn btn-primary">查询所有评论</button>
				</form>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>评论编号</th>
								<th>用户名</th>
								<th>书籍名</th>
								<th>评分</th>
								<th>评论内容</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.rows}" var="row">
								<tr>
									<td>${row.reviewid}</td>
									<td>${row.userid}</td>
									<td>${row.bookid}</td>
									<td>${row.rating}</td>
									<td>${row.comment}</td>
									<td><a href="#" class="btn btn-primary btn-xs"
										data-toggle="modal" data-target="#reviewEditDialog"
										onclick="editReview(${row.reviewid})">修改</a> <a href="#"
										class="btn btn-danger btn-xs"
										onclick="deleteReview(${row.reviewid})">删除</a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page
							url="${pageContext.request.contextPath }/review/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>

	<!-- 创建评论模态框 -->
	<div class="modal fade" id="newReviewDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">创建评论</h4>
				</div>
				<div class="modal-body">
					<form id="new_review_form">
						<div class="form-group">
							<label for="newuserId">用户编号:</label> <input type="text"
								id="newuserId" name="userid">
						</div>
						<div class="form-group">
							<label for="newbookId">书籍编号:</label> <input type="text"
								id="newbookId" name="bookid">
						</div>
						<div class="form-group">
							<label for="newPaymentMethod">评分:</label> <input type="number"
								id="newrating" name="rating" min="1" max="5">
						</div>
						<div class="form-group">
							<label for="newPaymentMethod">评论内容:</label> <textarea class="form-control" id="newComment" name="comment" rows="3"></textarea>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="createReview()">创建评论信息</button>
				</div>
			</div>
		</div>
	</div>

	<!-- 修改评论模态框 -->
	<div class="modal fade" id="reviewEditDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改评论信息</h4>
				</div>
				<div class="modal-body">
					<form id="editReviewForm" method="post">
						<div class="form-group">
							<label for="editedreviewId">评论编号:</label> <input type="text"
								id="editedreviewId" name="reviewid" readonly="readonly">
						</div>
						<div class="form-group">
							<label for="editeduserId">用户编号:</label> <input type="text"
								id="editeduserId" name="userid" readonly="readonly">
						</div>
						<div class="form-group">
							<label for="editedbookId">书籍编号:</label> <input type="text"
								id="editedbookId" name="bookid" readonly="readonly">
						</div>
						<div class="form-group">
							<label for="editedRating">评分:</label> <input type="number"
								class="form-control" id="editedRating" name="rating"
								min="1" max="5">
						</div>
						<div class="form-group">
							<label for="editedComment">评论内容:</label>
							<textarea class="form-control" id="editedComment"
								name="comment" rows="3"></textarea>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="updateReview()">保存修改</button>
				</div>
			</div>
		</div>
	</div>


	<!-- 引入js文件 -->
	<!-- jQuery -->
	<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="<%=basePath%>js/bootstrap.min.js"></script>
	<!-- Metis Menu Plugin JavaScript -->
	<script src="<%=basePath%>js/metisMenu.min.js"></script>
	<!-- DataTables JavaScript -->
	<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
	<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
	<!-- Custom Theme JavaScript -->
	<script src="<%=basePath%>js/sb-admin-2.js"></script>
	<!-- 编写js代码 -->
	<script type="text/javascript">
	
	//清空新建客户窗口中的数据
	function clearPayment() {
	    $("#newuserId").val("");
	    $("#newbookId").val("")
	    $("#newrating").val("");
	    $("#newComment").val("")
	}
	//创建支付
	function createReview() {
		$.post("<%=basePath%>review/create.action",
		$("#new_review_form").serialize(),function(data){
		        if(data =="OK"){
		            alert("评论信息创建成功！");
		            window.location.reload();
		        }else{
		            alert("评论信息创建失败！");
		            window.location.reload();
		        }
		    });
		}
	
	// 删除客户
	function deleteReview(id) {
	    if(confirm('确实要删除该评论吗?')) {
	$.post("<%=basePath%>review/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("评论删除成功！");
	                window.location.reload();
	            }else{
	                alert("评论删除失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
	

    // 执行修改客户操作
	function updateReview() {
		$.post("<%=basePath%>review/update.action",$("#editReviewForm").serialize(),function(data){
			if(data =="OK"){
				alert("评论信息更新成功！");
				window.location.reload();
			}else{
				alert("评论信息更新失败！");
				window.location.reload();
			}
		});
	}

	function editReview(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>review/getReviewById.action",
	        data:{"id":id},
	        success:function(data) {
	            $("#editedreviewId").val(data.reviewid);
	            $("#editeduserId").val(data.userid);
	            $("#editedbookId").val(data.bookid);
	            $("#editedRating").val(data.rating);
	            $("#editedComment").val(data.comment);
	        }
	    });
	}
    
    
	</script>
</body>
</html>
